package com.xinghai.system.service.impl;

import com.xinghai.common.utils.StringUtils;
import com.xinghai.system.domain.dto.*;
import com.xinghai.system.domain.vo.XhStaticsReportQueryVo;
import com.xinghai.system.mapper.XhVehicleInfoMaterialMapper;
import com.xinghai.system.mapper.XhVehicleOrderFeeMapper;
import com.xinghai.system.mapper.XhVehicleOrderInfoMapper;
import com.xinghai.system.service.XhStaticsReportService;
import com.xinghai.system.util.XHConstant;
import com.xinghai.system.util.XHUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class XhStaticsReportServiceImpl implements XhStaticsReportService {

    @Autowired
    private XhVehicleInfoMaterialMapper xhVehicleInfoMaterialMapper;

    @Autowired
    private XhVehicleOrderInfoMapper xhVehicleOrderInfoMapper;

    @Autowired
    private XhVehicleOrderFeeMapper xhVehicleOrderFeeMapper;

    @Override
    public List<ConsumablesDetailDTO> consumablesDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        if (StringUtils.isNotEmpty(xhStaticsReportQueryVo.getMaterialType())){
            //默认需求人耗材明细
            xhStaticsReportQueryVo.setMaterialType(XHConstant.STR_0);
        }
        List<ConsumablesDetailDTO> detailDTOList = xhVehicleInfoMaterialMapper.consumablesDetailPage(xhStaticsReportQueryVo);
        detailDTOList.forEach(item -> {
            //[{北京市,北京市,东城区=1111}, {河北省,唐山市,路北区=111}]
            if (StringUtils.isNotEmpty(item.getBeginAddr())) {
                item.setBeginAddr(XHUtils.parseBeginAddr(item.getBeginAddr()));
            }
        });
        return detailDTOList;
    }

    @Override
    public List<DebitDetailDTO> debitDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        List<DebitDetailDTO> detailDTOList = xhVehicleInfoMaterialMapper.debitDetailPage(xhStaticsReportQueryVo);
        detailDTOList.forEach(item -> {
            //[{北京市,北京市,东城区=1111}, {河北省,唐山市,路北区=111}]
            if (StringUtils.isNotEmpty(item.getBeginAddr())) {
                item.setBeginAddr(XHUtils.parseBeginAddr(item.getBeginAddr()));
            }
        });
        return detailDTOList;
    }

    @Override
    public List<DeptReconciliationDTO> deptReconciliationPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        List<DeptReconciliationDTO> reconciliationList = xhVehicleInfoMaterialMapper.deptReconciliationPage(xhStaticsReportQueryVo);
        reconciliationList.forEach(item -> {
            //[{北京市,北京市,东城区=1111}, {河北省,唐山市,路北区=111}]
            if (StringUtils.isNotEmpty(item.getBeginAddr())) {
                item.setBeginAddr(XHUtils.parseBeginAddr(item.getBeginAddr()));
            }
        });
        return reconciliationList;
    }

    @Override
    public List<ProjectFeeDetailDTO> projectFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        return xhVehicleOrderInfoMapper.projectFeeDetailPage(xhStaticsReportQueryVo);
    }

    @Override
    public List<DeptFeeDetailDTO> deptFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        return xhVehicleOrderInfoMapper.deptFeeDetailPage(xhStaticsReportQueryVo);
    }

    @Override
    public List<LoadFeeDetailDTO> loadFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        List<LoadFeeDetailDTO> detailList = xhVehicleOrderFeeMapper.loadFeeDetailPage(xhStaticsReportQueryVo);
        detailList.forEach(item -> {
            //[{北京市,北京市,东城区=1111}, {河北省,唐山市,路北区=111}]
            if (StringUtils.isNotEmpty(item.getBeginAddr())) {
                item.setBeginAddr(XHUtils.parseBeginAddr(item.getBeginAddr()));
            }
        });
        return detailList;
    }

    @Override
    public List<DeviceDetailDTO> deviceDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        return xhVehicleInfoMaterialMapper.deviceDetailPage(xhStaticsReportQueryVo);
    }

    @Override
    public List<TransferDetailDTO> transferDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        List<TransferDetailDTO> detailList = xhVehicleOrderInfoMapper.transferDetailPage(xhStaticsReportQueryVo);
        detailList.forEach(item -> {
            //[{北京市,北京市,东城区=1111}, {河北省,唐山市,路北区=111}]
            if (StringUtils.isNotEmpty(item.getBeginAddr())) {
                item.setBeginAddr(XHUtils.parseBeginAddr(item.getBeginAddr()));
            }
        });
        return detailList;
    }
}
